/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author snowangelic
 */
public class Cluster {
    private String name;
    private Color color;
    private Clusterization clusterAlgo;
    private Centroid centroid;
    private ArrayList<Action> actionList;
    private DataSet dataSet;

    Cluster(DataSet dataSet){
        this.dataSet=dataSet;
        centroid=new Centroid();
        actionList=new ArrayList<Action>();
    }

    public Cluster(DataSet dataSet,String n, Color c) {
        this.dataSet=dataSet;
        name=n;
        color=c;
        centroid=new Centroid();
        actionList=new ArrayList<Action>();
    }

    Cluster(String n,String c){
        name=n;
        color=StringToColor(c);
        centroid=new Centroid();
        actionList=new ArrayList<Action>();
    }

    public void setClusterization(Clusterization c){
        clusterAlgo=c;
    }

    public ArrayList<Weight> getWeightList() {
        return clusterAlgo.getWeightList();
    }

    public Centroid getCentroid() {
        return centroid;
    }

    private Color StringToColor(String c){
        Color col;
        if(c.equals("Red")) col=new Color(255,0,0);
        else if(c.equals("Green")) col=new Color(0,255,0);
        else if(c.equals("Blue")) col=new Color(0,0,255);
        else if(c.equals("Yellow")) col=new Color(255,255,0);
        else if(c.equals("Cyan")) col=new Color(0,255,255);
        else if(c.equals("Magenta")) col=new Color(255,0,255);
        else if(c.equals("Black")) col=new Color(0,0,0);
        else col=new Color(255,255,255);
        return col;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the color
     */
    public Color getColor() {
        return color;
    }

    /**
     * @param color the color to set
     */
    public void setColor(String c) {
        color=StringToColor(c);
    }

    public float[] getCoords(){
        return centroid.getCoords();
    }

    /**
     * @return the kmeans
     */
    public Clusterization getClusterizationAlgorithm() {
        return clusterAlgo;
    }

    public void addAction(Action action){
        if(actionList.contains(action)==false){
            actionList.add(action);
        }
    }

    public void setActionList(ArrayList<Action> actionList){
        this.actionList=actionList;
    }

    public ArrayList<Action> getActionList(){
        return actionList;
    }

    public void removeAction(Action action){
        if(actionList.contains(action)) actionList.remove(actionList.indexOf(action));
    }

    public void recomputePosition(){
        centroid.recomputePosition(actionList, dataSet);
    }

    public float getDistance(Action action,ArrayList<Weight> weightList,boolean normalized,Distance distance){
        return centroid.getDistanceFromAction(action, weightList, normalized, distance);
    }

    public float getDistance(Cluster cluster,ArrayList<Weight> weightList,boolean normalized,Distance distance){
        return centroid.getDistanceFromCluster(cluster, weightList, normalized, distance);
    }

    public Object getValue(Attribute attribute,boolean normalized){
        return centroid.getValue(attribute,normalized);
    }

    public boolean contains(Action action){
        return actionList.contains(action);
    }

}
